package duckHunter.sprites;

import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.media.MediaException;

import duckHunter.app.ApplicationResource;
import duckHunter.app.GameContext;
import duckHunter.ui.Level1;
import duckHunter.ui.SoundPlayer;
/**
 * BallSprite extends Sprite class
 * @author AYARI
 *
 */


public class BallSprite extends Sprite {
	//	private integer initial; 
	private int deltaY = -7;

	/** Constructor **/
	public BallSprite(Image image, int frameWidth, int frameHeight) {
		super(image);
		defineReferencePixel(frameWidth / 2, frameHeight / 2);

	}

	/** move the sprite vertically
	 * 
	 **/
	public void moveSprite(Level1 canvas, int w, int h) throws MediaException {
		// recover sprite position
		int y = getY();
		// if the sprite reaches the lower level of the screen it is removed
		if (y <= 20){
			canvas.getmLayerManager().remove(this);
		}
		// if the ball sprite touches the canard sound is played 
		//the number canard est incremented 
			
		//setting the position
		y += deltaY;
		setPosition(getX(), y);
	}
	// play an explosion sound
	public void playMidi(String file) {

		SoundPlayer player = new SoundPlayer(file);
		try {
			player.play();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (MediaException e) {
			e.printStackTrace();
		}
	}


}


